/*
 * Copyright 2009-2010 Original Author(s)
 * 
 * This file is part of Kommando
 * 
 * Kommando is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Kommando is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Kommando.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.kommando.filesystem.win32.objectsource;

import java.util.ArrayList;
import java.util.List;

import javax.swing.Icon;
import javax.swing.filechooser.FileSystemView;

import org.kommando.core.catalog.AbstractObjectSource;
import org.kommando.core.catalog.CachedObjectSource;
import org.kommando.core.catalog.CatalogObject;
import org.kommando.core.catalog.ObjectSource;
import org.kommando.filesystem.FileSystemCatalogObjectFactory;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Variant;

/**
 * {@link ObjectSource} for providing Windows special folders.
 * 
 * @author Peter De Bruycker
 */
public class SpecialFoldersObjectSource extends AbstractObjectSource implements CachedObjectSource {

    private static final String ID = "filesystem:specialFolders";

    @Override
    public String getDescription() {
        return "Special Folders";
    }

    @Override
    public Icon getIcon() {
        // TODO icon
        return null;
    }

    @Override
    public String getId() {
        return ID;
    }

    @Override
    public String getName() {
        return "Special Folders";
    }

    @Override
    public List<CatalogObject> getObjects() {
        List<CatalogObject> objects = new ArrayList<CatalogObject>();

        ComThread.InitSTA();

        // fetch special folders
        ActiveXComponent shell = new ActiveXComponent("WScript.Shell");
        String myDocuments = shell.invoke("SpecialFolders", new Variant("MyDocuments")).getString();
        String desktop = shell.invoke("SpecialFolders", new Variant("Desktop")).getString();
        shell.safeRelease();

        ComThread.Release();

        // objects.add(FileSystemCatalogObjectFactory.create(new File(myDocuments)));
        // objects.add(FileSystemCatalogObjectFactory.create(new File(desktop)));
        objects.add(FileSystemCatalogObjectFactory.create(FileSystemView.getFileSystemView().getHomeDirectory()));
        objects.add(FileSystemCatalogObjectFactory.create(FileSystemView.getFileSystemView().getRoots()[0]));

        /*
         * AllUsersDesktop AllUsersStartMenu AllUsersPrograms AllUsersStartup Desktop Favorites Fonts MyDocuments NetHood PrintHood Programs Recent SendTo
         * StartMenu Startup Templates
         */

        return objects;
    }

    @Override
    public CatalogObject getObject(String id) {
        // return new FileSystemObject(new File(id));
        return null;
    }
}
